﻿using System;
using System.Collections.Generic;
using MediatR;

namespace EasyDapr.Domain
{
    /// <summary>
    /// 领域事件接口
    /// </summary>
    public interface IDomainEvent : INotification
    {
        /// <summary>
        /// 创建时间
        /// </summary>
        DateTime CreatedAt { get; }

        /// <summary>
        /// 元数据
        /// </summary>
        IDictionary<string, object> MetaData { get; }
    }

    /// <summary>
    /// 领域事件上下文接口
    /// </summary>
    public interface IDomainEventContext
    {
        /// <summary>
        /// 获取领域事件列表
        /// </summary>
        /// <returns></returns>
        IEnumerable<DomainEventBase> GetDomainEvents();
    }

    /// <summary>
    /// 事件基类
    /// </summary>
    public abstract class EventBase : IDomainEvent
    {
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; } = DateTime.UtcNow;

        /// <summary>
        /// 元数据
        /// </summary>
        public IDictionary<string, object> MetaData { get; } = new Dictionary<string, object>();
    }

    /// <summary>
    /// 领域事件基类
    /// <remarks>用于进程内通讯</remarks>
    /// </summary>
    public abstract class DomainEventBase : EventBase
    {
    }

    /// <summary>
    /// 集成事件基类
    /// <remarks>用于进程外通讯</remarks>
    /// </summary>
    public abstract class IntegrationEventBase : EventBase
    {
    }

    /// <summary>
    /// 集成事件上下文接口
    /// </summary>
    public interface IIntegrationEventContext
    {
        /// <summary>
        /// 获取集成事件列表
        /// </summary>
        /// <returns></returns>
        IEnumerable<IntegrationEventBase> GetIntegrationEvents();
    }
}